<?php

/**
 * WeEngine System
 *
 * (c) We7Team 2021 <https://www.w7.cc>
 *
 * This is not a free software
 * Using it under the license terms
 * visited https://www.w7.cc for more details
 */

namespace W7\Addons\demo_engine_pc\Model\Logic;

use W7\Addons\demo_engine_pc\Model\Entity\News;
use W7\App\Model\Logic\BaseLogic;

class NewsLogic extends BaseLogic
{
    public function __construct()
    {
        $this->model = News::query();
    }

    public function lists(string $label = '')
    {
        if (!empty($label)) {
            $this->model->where('label', $label);
        }
        return $this->model->orderBy('id', 'desc')->get();
    }

    public function getMenu()
    {
        return $this->model->orderBy('id', 'desc')->get('label');
    }

    public function save(array $data)
    {
        return $this->model->updateOrCreate(['id' => $data['id']], $data);
    }

    public function delete(int $id)
    {
        return $this->model->where('id', $id)->delete();
    }
}
